package com.example.springbootmybatis.controller;

import com.example.springbootmybatis.model.User;
import com.example.springbootmybatis.service.UserService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: xulinyi
 * @create: 2019-03-07 11:00
 **/
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @GetMapping("/list")
    public List<User> getList() {
        return userService.getList();
    }

    @PostMapping("/add")
    public String add(User user) {
        try {
            userService.add(user);
            return "add success";
        } catch (Exception e) {
            return e.getMessage();
        }
    }

    @PutMapping("/update")
    public String update(User user) {
        try {
            userService.update(user);
            return "update success";
        } catch (Exception e) {
            return e.getMessage();
        }
    }

    @DeleteMapping("/del/{uid}")
    public String del(@PathVariable("uid") Integer uid) {
        try {
            userService.del(uid);
            return "del success";
        } catch (Exception e) {
            return e.getMessage();
        }
    }
}
